package graph;
public class Edge{
	
	private static final long serialVersionUID = 1L;
	
	private Vertex v1; //key for first vertex
	private Vertex v2; //key for second vertex
	private String label;
	private double[] weight; //list of weights
	
	private static double[] def_weight = {0.0,1.0};
	
	public Edge(Vertex v1, Vertex v2){
		
		this(v1,v2,"1",def_weight);
	}
	
	public Edge(Vertex v1, Vertex v2, String pLabel,double[] pWeight){
		this.v1 = v1; this.v2 = v2;
		this.label = pLabel;
		
		weight = new double[pWeight.length];
		System.arraycopy(pWeight, 0, this.weight, 0, pWeight.length);
	}
		
	public static double[] getDef_weight() {
		return def_weight;
	}

	public static void setDef_weight(double[] def_weight) {
		Edge.def_weight = def_weight;
	}

	public double[] getWeight() {
		return weight;
	}
	
	public double getWeight(int x){
		if(x<weight.length){
			return weight[x];
		}
		return -1.0; 
	}

	public void setWeight(double[] weight) {
		this.weight = weight;
	}
	
	public boolean setWeight(double x, int n){
		if(n<weight.length){
			this.weight[n] = x;
			return true;
		}
		else {
			return false;
		}
	}

	public String getLabel() {
		return label;
	}
	
	public String toString(){
		return "("+v1.toString()+","+v2.toString()+","+label+","+weight[0]+","+weight[1]+")";
	}
	
	public Vertex getV1() {
		return v1;
	}
	
	public boolean equals(Object o){
		if(o instanceof Edge){
			Edge e = (Edge)o;
			if(e.getV1().equals(v1) && e.getV2().equals(v2) && e.getLabel().equals(label)){
				return true;
			}
		return false;
		}
		return o.equals(this);
	}

	public void setV1(Vertex v1) {
		this.v1 = v1;
	}

	public Edge reverse(){
		return new Edge(v2,v1);
	}
	
	public Vertex getV2() {
		return v2;
	}

	public void setV2(Vertex v2) {
		this.v2 = v2;
	}

	public void setLabel(String label) {
		this.label = label;
	}
}